//
//  wUGBczJLCFHomeMsgCenterControllerlMWSIn.m
//  Dvjf_ios
//
//  Created by Ji on 2018/9/11.
//  Copyright © 2018年 ski. All rights reserved.
//

#import "wUGBczJLCFHomeMsgCenterControllerlMWSIn.h"
#import "IpxzlFJLCFHomeRequestPfjhYJ.h"
#import "oXlSXWJLCFHomeMsgCenterResultModeluMXJKS.h"
#import "nnqTtJJLCFHomeMsgCelltclBoF.h"
#import "bRINsvJLCFHomeActivityViewControllerhGuDnz.h"
#import "ygmJZCJLCFHomeMsgListControllerEVhAUy.h"

@interface wUGBczJLCFHomeMsgCenterControllerlMWSIn ()
{
    NSInteger _pageNumber;
}

@property (nonatomic, strong) oXlSXWJLCFHomeMsgCenterResultModeluMXJKS *TgzwxAresultModelZWmmrE;
@property (nonatomic, strong) NSMutableArray *msgArr;

@end

@implementation wUGBczJLCFHomeMsgCenterControllerlMWSIn

- (NSMutableArray *)msgArr
{
    if (!_msgArr) {
        _msgArr = [NSMutableArray array];
    }
    return _msgArr;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self addNavigationBar];
    self.navigationBar.title = @"消息中心";
    self.view.backgroundColor = QTZ_Gray237;
    
    self.tableView.height -= 103;
    self.tableView.top += 103;
    
    [self configHeaderView];
    
    [self loadData];
}

- (void)configHeaderView
{
    UIView *rRHNlxheaderViewfJQeRl = [[UIView alloc] initWithFrame:CGRectMake(0, NAVBAR_HEIGHT + 3, FULL_WIDTH, 100)];
    rRHNlxheaderViewfJQeRl.backgroundColor = QTZ_White;
    [self.view addSubview:rRHNlxheaderViewfJQeRl];
    
    CGFloat piece = FULL_WIDTH / 6;
    
    UIImageView *systemImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_msgCenter_system"]];
    systemImg.centerX = piece;
    systemImg.centerY = 45;
    systemImg.userInteractionEnabled = YES;
    [systemImg bk_whenTapped:^{
        ygmJZCJLCFHomeMsgListControllerEVhAUy *vc = [ygmJZCJLCFHomeMsgListControllerEVhAUy new];
        vc.zfNWacmsgCodeFdzEVY = @"0";
        vc.title = @"系统消息";
        [[[JinLiCaiFuApplicationEntrace shareEntrance] currentNavController] pushViewController:vc animated:YES];
    }];
    [rRHNlxheaderViewfJQeRl addSubview:systemImg];
    
    UILabel *systemLabel = [UILabel labelWithText:@"系统消息" textColor:QTZ_Gray51 font:FONT(10)];
    systemLabel.centerX = systemImg.centerX;
    systemLabel.top = systemImg.bottom + 4;
    [rRHNlxheaderViewfJQeRl addSubview:systemLabel];
    
    UIImageView *noticeImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_msgCenter_notice"]];
    noticeImg.centerX = piece * 3;
    noticeImg.centerY = systemImg.centerY;
    noticeImg.userInteractionEnabled = YES;
    [noticeImg bk_whenTapped:^{
        ygmJZCJLCFHomeMsgListControllerEVhAUy *vc = [ygmJZCJLCFHomeMsgListControllerEVhAUy new];
        vc.zfNWacmsgCodeFdzEVY = @"1";
        vc.title = @"公告中心";
        [[[JinLiCaiFuApplicationEntrace shareEntrance] currentNavController] pushViewController:vc animated:YES];
    }];
    [rRHNlxheaderViewfJQeRl addSubview:noticeImg];
    
    UILabel *uBShqXnoticeLabelBqMXlb = [UILabel labelWithText:@"公告中心" textColor:QTZ_Gray51 font:FONT(10)];
    uBShqXnoticeLabelBqMXlb.centerX = noticeImg.centerX;
    uBShqXnoticeLabelBqMXlb.top = systemLabel.top;
    [rRHNlxheaderViewfJQeRl addSubview:uBShqXnoticeLabelBqMXlb];
    
    UIImageView *messageImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_msgCenter_message"]];
    messageImg.centerX = piece * 5;
    messageImg.centerY = systemImg.centerY;
    messageImg.userInteractionEnabled = YES;
    [messageImg bk_whenTapped:^{
        [[[JinLiCaiFuApplicationEntrace shareEntrance] currentNavController] pushViewController:[bRINsvJLCFHomeActivityViewControllerhGuDnz new] animated:YES];
    }];
    [rRHNlxheaderViewfJQeRl addSubview:messageImg];
    
    UILabel *messageLabel = [UILabel labelWithText:@"官方通知" textColor:QTZ_Gray51 font:FONT(10)];
    messageLabel.centerX = messageImg.centerX;
    messageLabel.top = systemLabel.top;
    [rRHNlxheaderViewfJQeRl addSubview:messageLabel];
    
    
}

- (void)loadData
{
    
    [self.msgArr removeAllObjects];
    _pageNumber = 1;
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setSafeObject:@(_pageNumber) forKey:@"page"];
    
    [IpxzlFJLCFHomeRequestPfjhYJ msgCenterDataWithParams:params loadingInView:self.view success:^(oXlSXWJLCFHomeMsgCenterResultModeluMXJKS *home) {
        
        [self hideNoMoreDataNotice];
        if (home.data.count > 0) {
            [self.msgArr addObjectsFromArray:home.data];
        } else {
            self.tableView.tableHeaderView = nil;
            [self showNoMoreDataNotice:@"没有更多了"];
        }
        [self.tableView reloadData];
        [self endRefresh];
        
    } failure:^(NSString *error) {
        [self showNotice:error];
        [self endRefresh];
    }];
    
}

- (void)loadMoreData
{
    _pageNumber ++;
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setSafeObject:@(_pageNumber) forKey:@"page"];
    
    [IpxzlFJLCFHomeRequestPfjhYJ msgCenterDataWithParams:params loadingInView:self.view success:^(oXlSXWJLCFHomeMsgCenterResultModeluMXJKS *home) {
        
        if (home.data.count > 0) {
            
            [self.msgArr addObjectsFromArray:home.data];
        } else {
            self.tableView.mj_footer.hidden = YES;
            [self showNoMoreDataNotice:@"没有更多了"];
        }
        [self.tableView reloadData];
        [self endLoadMore];
        
    } failure:^(NSString *error) {
        [self showNotice:error];
        [self endRefresh];
    }];
    
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *rRHNlxheaderViewfJQeRl = [[UIView alloc] initWithFrame:CGRectMake(0, 0, FULL_WIDTH, 10)];
    rRHNlxheaderViewfJQeRl.backgroundColor = [UIColor clearColor];
    return rRHNlxheaderViewfJQeRl;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.msgArr.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 58;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    nnqTtJJLCFHomeMsgCelltclBoF *cell = [nnqTtJJLCFHomeMsgCelltclBoF dequeueReusableCellForTableView:tableView];
    cell.data = [self.msgArr safeObjectAtIndex:indexPath.section];
    [cell reloadData];
    return cell;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
